package com.ke.hibernate;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.ke.hibernate.dao.HibernateUtils;
import com.ke.hibernate.domain.Person;

public class Cri {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		cri("keke");
	}
	static void cri(String name)
	{
			Session s = null;
			try {
				s = HibernateUtils.getSession();
				Criteria c = s.createCriteria(Person.class);
				c.add(Restrictions.eq("name", name));
				c.add(Restrictions.lt("birthday", new Date()));
				c.setFirstResult(0);
				c.setMaxResults(10);
				List<Person> list = c.list();
				Person p = (Person) c.uniqueResult();
				System.out.println(p.getId());
				for(Person person:list){
					System.out.println(person.getName());
				}
			} finally
			{
				if(s!=null)
					s.close();
			}
		
	}

}
